//
//  ScanIdCardSuccessViewController.m
//  NewPro
//
//  Created by RYX on 2018/10/24.
//  Copyright © 2018年 何荧红. All rights reserved.
//

#import "ScanIdCardSuccessViewController.h"
#import "ScanIdList.h"
#import "ScanIdModel.h"
#import "AddFaceViewController.h"

@interface ScanIdCardSuccessViewController ()
{
    
    __weak IBOutlet UIView *bottomView;
    __weak IBOutlet UIImageView *idImgView;
    __weak IBOutlet UITextField *nameTf;
    __weak IBOutlet UITextField *genderTf;
    __weak IBOutlet UITextField *idNumTf;
    __weak IBOutlet UITextField *dateTf;
}
@end

@implementation ScanIdCardSuccessViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    
    
//    CALayer *layer = [CALayer layer];
//    layer.shadowOffset = CGSizeMake(0, 3);
//    //(0,0)时是四周都有阴影
//    layer.shadowRadius = 5.0;
//    layer.shadowColor = [UIColor blackColor].CGColor;
//    layer.shadowOpacity = 0.5;
//    bottomView.layer = layer;
    
    bottomView.layer.cornerRadius = 10;
    bottomView.layer.shadowColor = [UIColor blackColor].CGColor;
    bottomView.layer.shadowOpacity = 0.2f;
    bottomView.layer.shadowRadius = 4.f;
    bottomView.layer.shadowOffset = CGSizeMake(1,1);
    
    
    [self setNavBarWithTitle:@"实名认证"];
    
    [self setData];
    
}

- (void)setData{
    
    idImgView.image = [ScanIdList sharedInstance].scanModel.idFontImage;
    nameTf.text = [ScanIdList sharedInstance].scanModel.name;
    genderTf.text = [ScanIdList sharedInstance].scanModel.gender;
    idNumTf.text = [ScanIdList sharedInstance].scanModel.code;
    
    NSArray *arr = [[ScanIdList sharedInstance].scanModel.valid componentsSeparatedByString:@"-"];
    NSString *dateOne = arr[0];
    NSString *dateTwo = arr[1];
    NSRange range = NSMakeRange(4, 2);
    NSString *str = @"";
    if ([dateTwo isEqualToString:@"长期"]) {
        str = [NSString stringWithFormat:@"%@.%@.%@-%@",[dateOne substringToIndex:4],[dateOne substringWithRange:range],[dateOne substringFromIndex:6],dateTwo];
    }else{
        str = [NSString stringWithFormat:@"%@.%@.%@-%@.%@.%@",[dateOne substringToIndex:4],[dateOne substringWithRange:range],[dateOne substringFromIndex:6],[dateTwo substringToIndex:4],[dateTwo substringWithRange:range],[dateTwo substringFromIndex:6]];
    }
    dateTf.text = str;
}


- (IBAction)onNextBtn:(UIButton *)sender {
    
    if (nameTf.text.length <= 0) {
        
        return [self showMBPError:@"填写姓名"];
    }
    
    [ScanIdList sharedInstance].scanModel.name = nameTf.text;
    
    if (idNumTf.text.length <= 0) {
        
        return [self showMBPError:@"填写身份证号"];
    }
    
    [ScanIdList sharedInstance].scanModel.code = idNumTf.text;
    
    AddFaceViewController *VC = [[AddFaceViewController alloc] init];
    [self.navigationController pushViewController:VC animated:YES];
}
@end
